#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
   @Author: 叶建伟
   @Email: yejw46507@hundsun.com
   @Time: 2023/5/12 16:28
   @File: dataTest.py
"""
import random
from random import choice

import choice as choice
from faker import Faker

from DataTest.tabledata.commonData.SQLMontage import get_sql_key, montage_sql_value, read_file
from DataTest.tabledata.commonData.clientInfo import client_info

fake = Faker(locale='zh_CN')


def montage_sql(**kwargs):
    table = kwargs.get('table')
    sql_list = kwargs.get('sql_list')
    sql = read_file(table)
    for key, value in sql.items():
        table_value = {}
        for key_1, value_1 in value[0].items():
            keyLower = key_1.lower()
            table_value.update({keyLower: value_1})
        table_key = get_sql_key(table=table)
        values = montage_sql_value(table=table_value, sql_list=sql_list)
        print(table_key.lower()+values+';')



if __name__ == "__main__":
    dateList = [20240321,20240320,20240319,20240318,20240315,20240314,20240313,20240312,20240311,20240308]
    client_type = '0'
    # trade_status = '1'
    sql_list = client_info()
    client_id = '465070340001'
    sql_list.update({'client_id': client_id, 'inner_client_id': client_id, 'client_type': client_type})
    occupation_code = '1'
    sql_list.update({'occupation_code': occupation_code})

    # region_code = '440000'
    # sql_list.update({'region_code': region_code})
    # id_no = '53'+ sql_list.get('id_no')[2:]
    # sql_list.update({'id_no':id_no})
    montage_sql(table='fnd_client', sql_list=sql_list)
    montage_sql(table='fnd_fund_account', sql_list=sql_list)
    for i in range(3):
        business_flag = random.choice(['01', '02'])
        apply_no = 'sq' + str(fake.random_number(digits=8)) + str(fake.random_number(digits=6))
        occur_date = apply_date = confirm_date = random.choice(dateList)
        match_amount = 2000000
        if i == 3:
            occur_date = apply_date = confirm_date = 20240307
        sql_list.update({'business_flag':business_flag,'apply_no':apply_no,'occur_date': occur_date, 'apply_date': apply_date, 'confirm_date': confirm_date})
        montage_sql(table='fnd_request', sql_list=sql_list)


    # fund_account = 'hsjj'+str(fake.random_number(digits=8))+str(fake.random_number(digits=6)) #基金账户
    # sql_list.update({'fund_account':fund_account})
    # montage_sql(table='fnd_fund_account', sql_list=sql_list)
    # for i in range(2):
    #     apply_no = 'sq' + str(fake.random_number(digits=8)) + str(fake.random_number(digits=6))
    #     occur_date = apply_date = confirm_date = random.choice(dateList)
    #     match_amount = 1000000
    #     sql_list.update(
    #         {'apply_no': apply_no, 'occur_date': occur_date, 'apply_date': apply_date, 'confirm_date': confirm_date})
    #     montage_sql(table='fnd_request', sql_list=sql_list)








